package cn.edu.tju.core.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;

@Configuration//Tell the Spring container that this is a configuration class
public class SwaggerConfig {
    //Visit the website:http://127.0.0.1:8080/swagger-ui/index.html
    @Bean
    public OpenAPI springShopOpenAPI() {

        // 定义一个安全方案的名称，自定义
        final String securitySchemeName = "bearerAuth";

        return new OpenAPI()
                .info(new Info().title("TJU SE Project")
                        .description("Tianjin University Software Engineering Project")
                        .version("v1"))
                

                // 这是我们新增的全局安全认证需求
                .addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
                
                // 这是我们新增的具体安全方案定义
                .components(
                    new Components()
                        .addSecuritySchemes(securitySchemeName,
                            new SecurityScheme()
                                .name(securitySchemeName)
                                .type(SecurityScheme.Type.HTTP) // 认证类型为HTTP
                                .scheme("bearer")               // 具体的 scheme 为 bearer
                                .bearerFormat("JWT")            // 格式为 JWT
                        )
                );
        

    }

}